package com.example.demo.config;

import java.io.Serializable;

/**
 * 统一返回类型
 */
public class AjaxResult implements Serializable {

    private Integer code;
    private String msg;
    private Object data;

    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = 200;
        ajaxResult.msg = "成功";
        ajaxResult.data = data;
        return ajaxResult;
    }

    public static AjaxResult success(Object data, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = 200;
        ajaxResult.msg = msg;
        ajaxResult.data = data;
        return ajaxResult;
    }

    public static AjaxResult success(Object data, String msg, Integer code) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = code;
        ajaxResult.msg = msg;
        ajaxResult.data = data;
        return ajaxResult;
    }

    public static AjaxResult error(Object data, String msg, Integer code) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = code;
        ajaxResult.msg = msg;
        ajaxResult.data = data;
        return ajaxResult;
    }

    public static AjaxResult error(Object data, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = 403;
        ajaxResult.msg = msg;
        ajaxResult.data = data;
        return ajaxResult;
    }

    public static AjaxResult error(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = 403;
        ajaxResult.msg = "错误";
        ajaxResult.data = data;
        return ajaxResult;
    }
}
